//公用js
import Vue from 'vue'
import VueRouter from 'vue-router'
//总框架
import App from './App.vue'
//路由模版
import login from './page/home/login.vue'

import index from './page/manage/index.vue'
import ahome from './page/manage/index/ahome.vue'
import peo from './page/manage/index/peo.vue'
import sys from './page/manage/index/sys.vue'

import about from './page/other/about.vue'
//公用模版
import myComponent from './tpl/myComponent.vue'
Vue.component('myComponent', myComponent)
//路由配置
Vue.use(VueRouter); 

var routes = [
  { path: '/', component: login ,meta: { requiresAuth: false }},
  { path: '/index', component: index, redirect: '/index/ahome',meta: { requiresAuth: true }, 
  		children: [
        {
          path: 'ahome',meta: { requiresAuth: true },
          component: ahome
        },
        {
          path: 'peo',meta: { requiresAuth: true },
          component: peo
        },
        {
          path: 'sys',meta: { requiresAuth: true },
          component: sys
        }
      ]
  },
  { path: '/about', component: about,meta: { requiresAuth: false } }
]
var router = new VueRouter({
  routes: routes // （缩写）相当于 routes: routes
})
//导航钩子

router.beforeEach(function (to, from, next){
	
		console.log(to,"即将要进入的目标 路由对象");
		console.log(from,"当前导航正要离开的路由");
		if(to.meta.requiresAuth){
			if(isLogin){
				next()
			}else{
				next({
					path: '/'
				});
			};
		}else{
			next();
		};
	
})

//vuex 状态机

import store from './store/store.js'


//实例化
new Vue({
  router:router,
  store:store,
  render: function(createElement){
	  return createElement(App)
  },
  created: function () {
    console.log("vue实例化完成");
  }
}).$mount('#app')



